home *** CD-ROM | disk | FTP | other *** search
/ Programming Microsoft Visual Basic .NET / Programming Microsoft Visual Basic .NET (Microsoft Press)(X08-78517)(2002).bin / 25 user and custom controls / customcontrollibrary / tablecontrol.vb < prev   
Encoding:
Text File  |  2002-03-19  |  5.2 KB  |  175 lines

  1. Imports System.ComponentModel
  2. Imports System.Web.UI
  3.  
  4. <ToolboxData("<{0}:TableControl runat=server></{0}:TableControl>")> _
  5. Public Class TableControl
  6.     Inherits System.Web.UI.WebControls.WebControl
  7.  
  8.     ' the CellBorderStile property shows how an enumerated
  9.     ' property appears in the Properties window at design time
  10.     ' (this property is ignored in the HTML generation)
  11.     Dim m_CellBorderStyle As System.Web.UI.WebControls.BorderStyle
  12.  
  13.     <Description("The border style of table cells")> _
  14.     Property CellBorderStyle() As System.Web.UI.WebControls.BorderStyle
  15.         Get
  16.             Return m_CellBorderStyle
  17.         End Get
  18.         Set(ByVal Value As System.Web.UI.WebControls.BorderStyle)
  19.             m_CellBorderStyle = Value
  20.         End Set
  21.     End Property
  22.  
  23.     ' The Rows property
  24.  
  25.     Dim m_Rows As Integer = 3
  26.  
  27.     <Bindable(True), Category("Appearance"), DefaultValue(3), _
  28.       Description("The number of rows")> _
  29.     Property Rows() As Integer
  30.         Get
  31.             Return m_Rows
  32.         End Get
  33.         Set(ByVal Value As Integer)
  34.             If Value > 0 Then
  35.                 m_Rows = Value
  36.             End If
  37.         End Set
  38.     End Property
  39.  
  40.     ' The Columns  property
  41.  
  42.     Dim m_Columns As Integer = 4
  43.  
  44.     <Bindable(True), Category("Appearance"), DefaultValue(4), _
  45.       Description("The number of columns")> _
  46.     Property Columns() As Integer
  47.         Get
  48.             Return m_Columns
  49.         End Get
  50.         Set(ByVal Value As Integer)
  51.             If Value > 0 Then
  52.                 m_Columns = Value
  53.             End If
  54.         End Set
  55.     End Property
  56.  
  57.     ' This method is where we actually send the output to the client
  58.  
  59.     Protected Overrides Sub Render(ByVal output As System.Web.UI.HtmlTextWriter)
  60.         Dim r, c As Integer
  61.  
  62.         ' create the <table> tag
  63.         output.AddAttribute("border", "1")
  64.         output.RenderBeginTag("table")
  65.         output.WriteLine()
  66.         output.Indent += 1
  67.  
  68.         ' render each table row
  69.         For r = 1 To Rows
  70.             output.RenderBeginTag("tr")
  71.             output.WriteLine()
  72.             output.Indent += 1
  73.             ' render each column on the row
  74.             For c = 1 To Columns
  75.                 output.RenderBeginTag("td")
  76.                 output.Write(r.ToString & "," & c.ToString)
  77.                 output.RenderEndTag()
  78.                 output.WriteLine()
  79.             Next
  80.             ' output a closing tag </TR>
  81.             output.Indent -= 1
  82.             output.RenderEndTag()
  83.             output.WriteLine()
  84.         Next
  85.         ' output a closing tag </TABLE>
  86.         output.Indent -= 1
  87.         output.RenderEndTag()
  88.     End Sub
  89.  
  90.     ' The ImageUrl property demonstrates how you can re-use a property
  91.     ' editor defined in the framework
  92.     ' (This property is ignored during HTML code generation)
  93.     Dim m_ImageUrl As String
  94.  
  95.     <EditorAttribute("System.Web.UI.Design.ImageUrlEditor, System.Design, " _
  96.     & "Version=1.0.3300.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a", GetType(System.Drawing.Design.UITypeEditor))> _
  97.     Property ImageUrl() As String
  98.         Get
  99.             Return m_ImageUrl
  100.         End Get
  101.         Set(ByVal Value As String)
  102.             m_ImageUrl = Value
  103.         End Set
  104.     End Property
  105.  
  106.     ' The CellFont property demonstrates that a FontInfo property
  107.     ' inherits the editor defined in the framework
  108.     ' (This property is ignored during HTML code generation)
  109.  
  110.     Dim m_CellFont As System.Web.UI.WebControls.FontInfo = MyBase.Font
  111.  
  112.     Property CellFont() As System.Web.UI.WebControls.FontInfo
  113.         Get
  114.             Return m_CellFont
  115.         End Get
  116.         Set(ByVal Value As System.Web.UI.WebControls.FontInfo)
  117.             m_CellFont = Value
  118.         End Set
  119.     End Property
  120.  
  121.     ' The BackColor property shows how you can override a property
  122.     ' with the only goal of hiding it in the Properties window
  123.  
  124.     <Browsable(False)> _
  125.     Overrides Property BackColor() As System.Drawing.Color
  126.         Get
  127.             Return System.Drawing.Color.White
  128.         End Get
  129.         Set(ByVal Value As System.Drawing.Color)
  130.             ' Ignore this assignment.
  131.         End Set
  132.     End Property
  133.  
  134.     ' The CellStyle property shows how a property that return a custom
  135.     ' object appears in the Properties window
  136.  
  137.     Dim m_CellStyle As New CellStyle()
  138.  
  139.     Property CellStyle() As CellStyle
  140.         Get
  141.             Return m_CellStyle
  142.         End Get
  143.         Set(ByVal Value As CellStyle)
  144.             m_CellStyle = Value
  145.         End Set
  146.     End Property
  147.  
  148. End Class
  149.  
  150. ' This is a custom class used to demonstrate the CellStyle property
  151.  
  152. Public Class CellStyle
  153.  
  154.     Dim m_ForeColor As System.Drawing.Color
  155.     Dim m_BackColor As System.Drawing.Color
  156.  
  157.     Property ForeColor() As Drawing.Color
  158.         Get
  159.             Return m_ForeColor
  160.         End Get
  161.         Set(ByVal Value As Drawing.Color)
  162.             m_ForeColor = Value
  163.         End Set
  164.     End Property
  165.  
  166.     Property BackColor() As Drawing.Color
  167.         Get
  168.             Return m_BackColor
  169.         End Get
  170.         Set(ByVal Value As Drawing.Color)
  171.             m_BackColor = Value
  172.         End Set
  173.     End Property
  174. End Class
  175.